# @Version        : 1.0
# @Update Time    : 2024/7/11 21:56
# @File           : menu_crud.py
# @IDE            : PyCharm
# @Desc           : 文件描述信息
from advanced_alchemy.base import BigIntAuditBase

from src.core.base.orm.orm import AbstractORMModel
from sqlalchemy.orm import Mapped, mapped_column
from sqlalchemy import String, Integer, Boolean, ForeignKey, BigInteger, Index


# class SysMenu(AbstractORMModel):
#     __tablename__ = "sys_menu"
#     __table_args__ = {"comment": "菜单表"}
#
#     status: Mapped[str] = mapped_column(
#         String(1), default="1", comment="菜单状态1正常，2禁用"
#     )
#     parent_id: Mapped[int] = mapped_column(Integer, comment="父菜单ID")
#     menu_type: Mapped[str] = mapped_column(
#         String(1), comment="菜单类型; 1:目录，2:菜单，3: 按钮"
#     )
#     permissions: Mapped[str | None] = mapped_column(
#         String(100), nullable=True, default=None, comment="权限标识"
#     )
#     menu_name: Mapped[str] = mapped_column(String(64), comment="菜单名称")
#     route_name: Mapped[str | None] = mapped_column(String(64), comment="路由名称")
#     route_path: Mapped[str | None] = mapped_column(String(64), comment="路由路径")
#     component: Mapped[str | None] = mapped_column(String(64), comment="组件路径")
#     order: Mapped[int] = mapped_column(Integer, comment="排序")
#     i18n_key: Mapped[str | None] = mapped_column(String(64), comment="国际化Key")
#     icon: Mapped[str | None] = mapped_column(String(64), comment="图标")
#     icon_type: Mapped[str | None] = mapped_column(String(64), comment="图标类型")
#
#     path_param: Mapped[str | None] = mapped_column(String(200), comment="路径参数")
#     route_param: Mapped[str | None] = mapped_column(
#         String(200), comment="路由参数, List[dict]"
#     )
#     href: Mapped[str | None] = mapped_column(String(200), comment="外链")
#     multiple_tab: Mapped[bool | None] = mapped_column(
#         Boolean, default=False, comment="是否支持多页签"
#     )
#     keep_alive: Mapped[bool] = mapped_column(Boolean, default=False, comment="是否缓存")
#     hide_in_menu: Mapped[bool] = mapped_column(
#         Boolean, default=False, comment="是否在菜单隐藏"
#     )
#     active_menu: Mapped[str | None] = mapped_column(
#         String(100), comment="隐藏的路由需要激活的菜单"
#     )
#     fixed_index_in_tab: Mapped[int | None] = mapped_column(
#         Integer, comment="固定在页签的序号"
#     )
#     redirect: Mapped[str | None] = mapped_column(String(200), comment="重定向路径")
#     props: Mapped[bool | None] = mapped_column(
#         Boolean, default=False, comment="是否为首路由"
#     )
#     constant: Mapped[bool | None] = mapped_column(
#         Boolean, default=False, comment="是否为公共路由"
#     )


class SysMenu(BigIntAuditBase):
    __tablename__ = "sys_menu"
    __table_args__ = (
        Index("ix_sys_menu_status", "status"),
        Index("ix_sys_menu_parent_id", "parent_id"),
        Index("ix_sys_menu_menu_type", "menu_type"),
        Index("ix_sys_menu_permissions", "permissions"),
        Index("ix_sys_menu_route_name", "route_name"),
        Index("ix_sys_menu_route_path", "route_path"),
        {"comment": "菜单表"},
    )

    parent_id: Mapped[int | None] = mapped_column(
        BigInteger,
        ForeignKey("sys_menu.id", ondelete="SET NULL"),
        nullable=True,
        comment="父菜单ID",
    )
    menu_type: Mapped[str] = mapped_column(
        String(1), comment="菜单类型; 1:目录，2:菜单，3: 按钮"
    )
    permissions: Mapped[str | None] = mapped_column(
        String(100), nullable=True, default=None, comment="权限标识"
    )
    menu_name: Mapped[str] = mapped_column(String(64), comment="菜单名称")
    route_name: Mapped[str | None] = mapped_column(String(64), comment="路由名称")
    route_path: Mapped[str | None] = mapped_column(String(64), comment="路由路径")
    component: Mapped[str | None] = mapped_column(String(64), comment="组件路径")
    order: Mapped[int] = mapped_column(Integer, comment="排序")
    i18n_key: Mapped[str | None] = mapped_column(String(64), comment="国际化Key")
    icon: Mapped[str | None] = mapped_column(String(64), comment="图标")
    icon_type: Mapped[str | None] = mapped_column(String(64), comment="图标类型")

    path_param: Mapped[str | None] = mapped_column(String(200), comment="路径参数")
    route_param: Mapped[str | None] = mapped_column(
        String(200), comment="路由参数, List[dict]"
    )
    href: Mapped[str | None] = mapped_column(String(200), comment="外链")
    multiple_tab: Mapped[bool | None] = mapped_column(
        Boolean, default=False, comment="是否支持多页签"
    )
    keep_alive: Mapped[bool] = mapped_column(Boolean, default=False, comment="是否缓存")
    hide_in_menu: Mapped[bool] = mapped_column(
        Boolean, default=False, comment="是否在菜单隐藏"
    )
    active_menu: Mapped[str | None] = mapped_column(
        String(100), comment="隐藏的路由需要激活的菜单"
    )
    fixed_index_in_tab: Mapped[int | None] = mapped_column(
        Integer, comment="固定在页签的序号"
    )
    redirect: Mapped[str | None] = mapped_column(String(200), comment="重定向路径")
    props: Mapped[bool | None] = mapped_column(
        Boolean, default=False, comment="是否为首路由"
    )
    constant: Mapped[bool | None] = mapped_column(
        Boolean, default=False, comment="是否为公共路由"
    )
    status: Mapped[str] = mapped_column(
        String(1), default="1", comment="菜单状态1正常，2禁用"
    )
